﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Drawing;

namespace EpiMapit
{
	public class Square : KmlFigureBase
	{
		public float Lat { get; set; }
		public float Lon { get; set; }
		public float Size { get; set; }

        public override XElement Kml
        {
            get
            {
                var builder = new StringBuilder();
                builder.Append(string.Format("{0},{1} ", Lon - Size / 2, Lat - Size / 2));
                builder.Append(string.Format("{0},{1} ", Lon + Size / 2, Lat - Size / 2));
                builder.Append(string.Format("{0},{1} ", Lon + Size / 2, Lat + Size / 2));
                builder.Append(string.Format("{0},{1} ", Lon - Size / 2, Lat + Size / 2));

                return new XElement("Polygon",
                    new XElement("outerBoundaryIs",
                        new XElement("LinearRing",
                            new XElement("coordinates", builder.ToString()))));
            }
        }

		public override BoundingBox BoundingBox
		{
			get
			{
				return new BoundingBox(Lat + Size / 2, Lat - Size / 2, Lon + Size / 2, Lon - Size / 2);
			}
		}
	}
}
